import request from '@/utils/request'

// 预测接口类型定义
export interface PredictionParams {
  timeRange: number
  goodsTypes: string[]
  modelType: string
  historyRange: string[]
  confidenceThreshold: number
  considerSeasonality: boolean
}

export interface PredictionResult {
  totalOutbound: number
  totalInbound: number
  totalGoods: number
  outboundTrend: number
  inboundTrend: number
  goodsTrend: number
  details: PredictionDetail[]
  modelMetrics: ModelMetrics
}

export interface PredictionDetail {
  date: string
  outbound: number
  inbound: number
  goods: number
  confidence: number
  modelAccuracy: number
  historicalValue?: number
  notes?: string
}

export interface ModelMetrics {
  r2: number
  mae: number
  rmse: number
  trainingTime: number
}

// ML.net预测接口
export const mlPredict = (params: PredictionParams) => {
  return request.post<{ success: boolean; data: PredictionResult; message?: string }>('/api/prediction/ml-predict', params)
}

// 获取商品类型列表
export const getGoodsTypes = () => {
  return request.get('/api/goods/types')
}

// 获取历史数据
export const getHistoricalData = (params: {
  startDate: string
  endDate: string
  goodsTypes?: string[]
}) => {
  return request.get('/api/prediction/historical-data', { params })
}

// 获取模型评估报告
export const getModelReport = (modelId: string) => {
  return request.get(`/api/prediction/model-report/${modelId}`)
}

// 导出预测结果
export const exportPredictionResults = (predictionId: string, format: 'excel' | 'pdf' | 'csv') => {
  return request.get(`/api/prediction/export/${predictionId}`, {
    params: { format },
    responseType: 'blob'
  })
}

// 保存预测配置
export const savePredictionConfig = (config: {
  name: string
  description: string
  params: PredictionParams
}) => {
  return request.post('/api/prediction/config', config)
}

// 获取预测配置列表
export const getPredictionConfigs = () => {
  return request.get('/api/prediction/configs')
}

// 删除预测配置
export const deletePredictionConfig = (configId: string) => {
  return request.delete(`/api/prediction/config/${configId}`)
} 